home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / ubiquity / clock-setup / finish-install < prev   
Encoding:
Text File  |  2009-04-19  |  2.8 KB  |  136 lines

  1. #!/bin/sh
  2. set -e
  3.  
  4. . /usr/share/debconf/confmodule
  5.  
  6. log() {
  7.     logger -t clock-setup "$@"
  8. }
  9. warning() {
  10.     log "warning: $*"
  11. }
  12.  
  13. os_needs_local_clock () {
  14.     while read line; do
  15.         shortname=$(echo "$line" | cut -d : -f 3)
  16.         case $shortname in
  17.         MS-DOS*|Windows*|FreeDOS*|Solaris*) # keep in sync with os-prober
  18.             return 0
  19.         ;;
  20.         esac
  21.     done
  22.     return 1
  23. }
  24.  
  25. pri=high
  26.  
  27. if db_fget clock-setup/utc seen && [ "$RET" = true ]; then
  28.     # keep preseeded value
  29.     :
  30. else
  31.     # os-prober is may not yet be installed..
  32.     anna-install os-prober-udeb || true
  33.  
  34.     probed=$(os-prober) || true
  35.  
  36.     if echo "$probed" | os_needs_local_clock; then
  37.         # default to localtime for some OSes
  38.         db_set clock-setup/utc false
  39.         pri=low
  40.     fi
  41.  
  42.     if [ -z "$probed" ]; then
  43.         # installing the only OS, so use UTC
  44.         db_set clock-setup/utc true
  45.         db_get clock-setup/utc-auto
  46.         if [ "$RET" = true ]; then
  47.             pri=low
  48.         fi
  49.     fi
  50. fi
  51.  
  52. db_input $pri clock-setup/utc || true
  53. if ! db_go; then
  54.     exit 10 # back to main menu
  55. fi
  56.  
  57. rcsfile=/target/etc/default/rcS
  58. adjtimefile=/target/etc/adjtime
  59.  
  60. db_get clock-setup/utc
  61. if [ "$RET" = true ]; then
  62.     sed -i -e 's:^UTC="no":UTC="yes":' -e 's:^UTC=no:UTC=yes:' $rcsfile
  63.     if [ -e "$adjtimefile" ]; then
  64.         sed -i -e 's:^LOCAL:UTC:' $adjtimefile
  65.     fi
  66. else
  67.     sed -i -e 's:^UTC="yes":UTC="no":' -e 's:^UTC=yes:UTC=no:' $rcsfile
  68.     if [ -e "$adjtimefile" ]; then
  69.         sed -i -e 's:^UTC:LOCAL:' $adjtimefile
  70.     fi
  71. fi
  72.  
  73. anna-install rtc-modules || true
  74.  
  75. # This may not be necessary on all hardware; hwclock can do direct IO if
  76. # the rtc module is not loaded.
  77. log-output -t hw-detect modprobe -v rtc || log "rtc module not loaded"
  78. log-output -t hw-detect modprobe -v rtc-dev || log "rtc-dev module not loaded"
  79. update-dev --settle
  80.  
  81. # rtc-dev creates a /dev/rtc0, so set up a symlink
  82. # XXX This won't be needed once a new udev (116) that
  83. # handles the symlink gets into Debian.
  84. if [ -e /dev/rtc0 ] && [ ! -e /dev/rtc ]; then
  85.     ln -sf rtc0 /dev/rtc
  86. fi
  87.  
  88. # bind mount /dev into /target/dev so that rtc devices are available for hwclock
  89. if mount -o bind /dev /target/dev; then
  90.     target_dev_mounted=1
  91. else
  92.     warning "failed to bind mount /target/dev"
  93. fi
  94.  
  95. cleanup () {
  96.     if [ "$target_dev_mounted" ] && ! umount /target/dev; then
  97.         warning "failed to unmount /target/dev bind mount"
  98.     fi
  99. }
  100.  
  101. db_progress INFO clock-setup/progress/hwclock
  102. log-output -t clock-setup chroot /target hwclock --systohc --debug &
  103. pid="$!"
  104. count=0
  105.  
  106. stop_hwclock () {
  107.     kill $pid || return
  108.     sleep 1
  109.     if [ -e /proc/$pid ]; then
  110.         kill -9 $pid || return
  111.     fi
  112. }
  113.  
  114. while sleep 1; do
  115.     if [ ! -e /proc/$pid ]; then
  116.         break
  117.     fi
  118.     count=$(expr $count + 1)
  119.     if [ "$count" = 30 ]; then
  120.         count=0
  121.         db_input critical clock-setup/hwclock-wait || true
  122.         if ! db_go; then
  123.             stop_hwclock
  124.             cleanup
  125.             exit 10 # back to main menu
  126.         fi
  127.         db_get clock-setup/hwclock-wait
  128.         if [ "$RET" = false ]; then
  129.             stop_hwclock
  130.             break
  131.         fi
  132.     fi
  133. done
  134.  
  135. cleanup
  136.